﻿using B.S.BaseData.ErrorCode;
using B.S.BaseData.Read.Api.Application.Command;
using B.S.BaseData.Read.Api.Application.Command.RoleCommand;
using B.S.BaseData.Read.Api.Application.Command.UserRoleCommand;
using B.S.BaseData.Read.Api.Dtos;
using B.S.BaseData.Write.Api.Application.Command;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MainController : ControllerBase
    {

        private readonly IMediator mediator;
        private readonly ILogger<MainController> logger;

        public MainController(IMediator mediator, ILogger<MainController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<List<GetMainDto>>> Handle([FromQuery]GetMainCommand request) {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
       

        /// <summary>
        /// 显示菜单处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<GetMenuDto>>> GetMenu([FromQuery]GetMenuCommand request) {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询菜单处理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<CascadeDto>>> GetMenuCascade([FromQuery]GetMenuCascadeCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 反添角色权限操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<AdditiveRoleDto>>> AdditiveRole([FromQuery]AdditiveRoleCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
